PK2CMD = pk2cmd -PPIC18F2550
PROCESSOR = 18f2550
PROCESSOR_SIM = 18f2455
SDCC = /opt/local/bin/sdcc
GPLINK = /opt/local/bin/gplink
GPASM = /opt/local/bin/gpasm
GPSIM =/usr/local/bin/gpsim

all:	kodak_timer
sim:	kodak_timer_sim sim

kodak_timer: kodak_timer.c
	$(SDCC) \
	--verbose \
	-V \
	-mpic16 \
	--use-crt=crt0.o \
	--use-non-free \
	-p$(PROCESSOR) \
	-Wl '-m' \
	$<

kodak_timer_master: kodak_timer_master.c
	$(SDCC) \
	--verbose \
	-V \
	-mpic16 \
	--use-crt=crt0.o \
	--use-non-free \
	-p$(PROCESSOR) $<

kodak_timer_sim: kodak_timer.c
	$(SDCC) \
	--verbose \
	-V \
	-mpic16 \
	--use-crt=crt0.o \
	--use-non-free \
	-p$(PROCESSOR_SIM) \
	-Wl '-m' \
	$<

kodak_timer.hex: kodak_timer.o
	$(GPLINK) \
	-c \
	-o $@ \
	-m \
	-r \
	-d \
	kodak_timer kodak_timer.o crt0.o \
	$^


kodak_timer.o: kodak_timer.asm
	$(GPASM) \
	--extended \
	-pp$(PROCESSOR) \
	-c $<

kodak_timer.asm: kodak_timer.c
	$(SDCC) \
	-V \
	--verbose \
	-S \
	--debug \
	-mpic16 \
	--use-crt=crt0.o \
	--use-non-free \
	-p$(PROCESSOR) $<

clean:
	rm -f *.adb *.asm *.cod *.cof *.hex *.lst *.map *.o *.sym *.lib

sim:
	$(GPSIM) -pp$(PROCESSOR_SIM) -c kodak_timer.stc -s kodak_timer.cod kodak_timer.asm && killall -9 X11.bin

flash:
	$(PK2CMD) -F kodak_timer.hex -M

flash_master:
	$(PK2CMD) -F kodak_timer_master.hex -M

on:
	$(PK2CMD) -R -T

off:
	$(PK2CMD) -R

